package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 86188
 * @version v1.0
 * @project ShangTingApartment
 * @Date 2025/7/8 15:25
 * @company []
 * @description
 */
@RestControllerAdvice
public class GlobalExceptionHandlers {
    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception e){
        System.out.println("GlobalExceptionHandlers.exceptionHandler");
        //记录日志
        e.printStackTrace();
        //返回提示
        return Result.fail(e.getMessage());
    }
    @ExceptionHandler(EnumException.class)
    public Result EnumExceptionHandler(EnumException e){
        System.out.println("GlobalExceptionHandlers.EnumExceptionHandler");
        return Result.fail(e.getCode(), e.getMessage());
    }

}
